import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:todo_app/models/todo_model.dart';
import 'package:todo_app/pages/providers/todo_filter/todo_filter_provider.dart';

class FilterTodo extends ConsumerWidget {
  const FilterTodo({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        FilterButton(Filter.all),
        FilterButton(Filter.active),
        FilterButton(Filter.completed),
      ],
    );
  }
}

class FilterButton extends ConsumerWidget {
  final Filter filter;
  const FilterButton(this.filter, {super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final selectedFilter = ref.watch(todoFilterProvider);
    return TextButton(
      onPressed: () {
        ref.read(todoFilterProvider.notifier).changeFilter(filter);
      },
      child: Text(
        filter == Filter.all
            ? "全部"
            : filter == Filter.active
            ? "待办"
            : "已完成",
        style: TextStyle(
          fontSize: 18,
          color: selectedFilter == filter ? Colors.blue : Colors.grey,
        ),
      ),
    );
  }
}
